
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="button" value="点我" id="btn1">
<script>
    var btn1 = document.getElementById('btn1');


    var foo = function(e){
        alert("aa")
    }

    var foo2 = function(e){
        alert("bbb")
    }

    function myAddEvent(obj,type,listener,useCapture){
        if (obj.addEventListener){
            obj.addEventListener(type,listener,useCapture)
        } else {
            obj.attachEvent('on'+type,listener)
        }
    }
    function myRemoveEvent(obj,type,listener){
        if (obj.removeEventListener){
            obj.removeEventListener(type,listener)
        } else {
            obj.detachEvent('on'+type,listener)
        }
    }
    myAddEvent(btn1,'click',foo);
    myAddEvent(btn1,'click',foo2);
    myRemoveEvent(btn1,'click',foo);
//    btn1.addEventListener('click',foo);
//    btn1.attachEvent('onclick',foo)
</script>
</body>
</html>